package com.it.反射;

import java.lang.management.ManagementFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Student {

    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        System.out.println("ABCDEa".hashCode());  // 165374702

        System.out.println("ABCDFB".hashCode()); //  165374702
        ArrayList<Integer> strList = new ArrayList<>();
        strList.add(1);
        strList.add(2);

        //	strList.add(100);
        //获取ArrayList的Class对象，反向的调用add()方法，添加数据
        Class listClass = strList.getClass(); //得到 strList 对象的字节码 对象
        //获取add()方法
        Method m = listClass.getMethod("add", Object.class);
        //调用add()方法
        m.invoke(strList, "aaa");

        //遍历集合
        for(Object obj : strList){
            System.out.println(obj);
        }
        Date date=new Date();
        int n=-1;
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
        gc.setTime(date);
        gc.add(Calendar.DATE, n);
        System.out.println( gc.getTime());
        String fullPid = ManagementFactory.getRuntimeMXBean().getName();
        String pid = fullPid.split("@")[0];
        System.out.println(pid);

    }
}
